﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using KFGame;
using System;
namespace KFGame
{
    public class YearLog
    {
        public string logtype = "year";

        KFDataFile dataFile = new KFDataFile();

        public List<string> listlabes = new List<string>();

        public List<long> listDatas = new List<long>();

        string title;


        int year;
        public YearLog(string n)
        {
            title = n;
            DateTime t = DateTime.Now;

            year = t.Year;

        }

        public void setYear(int y)
        {
            year = y;
        }


        //加载偏移 
        public void load(int offset = 0)
        {
            year += offset;

            DateTime t = DateTime.Now;
            dataFile.title = title;
            dataFile.type = logtype;
            dataFile.consent = year.ToString();

            string[] datas = dataFile.read();
            if (datas == null) return;
            if (datas.Length < 2) return;

            listlabes.Add(datas[0]);
            listDatas.Add(Convert.ToInt64(datas[1]));
        }

        //添加数据
        public void addDatas(long d)
        {
            if (listlabes.Count == 0)
                listlabes.Add(year.ToString());
            else
                listlabes[0] = year.ToString();

            if (listDatas.Count == 0)
                listDatas.Add(d);
            else
                listDatas[0] += d;
        }

        //保存数据
        public void save()
        {
            string[] data = new string[2];
            data[0] = string.Join("", listlabes.ToArray());
            data[1] = string.Join("", listDatas.ToArray());
            dataFile.save(data);
        }
    }
}